Hello, I am fairly new to DXL and thus running in to some trouble. I have a doors module with few thousand objects which I wish to rearrange based on a list of object headings. Here is my attempt, however it does not work as expected.
pragma runLim, 0
Module m = current
Object o
Object oPrev = first(m)
int index = 0
string str
Skip fileLines = create
// Choose files and read it
string filepath = "C:\\Users\\USERNAME\\Desktop\\list.txt" // list containing headings
Stream input = read(filepath)
while (true)
{
input >> str
if(end of input) break
put(fileLines, index++, str)
}
for o in m do
{
string CM = o."Code Moved"
if (CM == "")
{
string OH = o."Object Heading"
for str in fileLines do
{
if ((OH == str))
{
if (o != oPrev)
{
move(o,oPrev)
o."Code Moved" = "Yes"
oPrev = o
}
}
}
}
}
The "List.txt" file contains object headings, some what like this: Customer Documents Government Documents Industry Documents Supplier Documents
DOORS_user - Thu Sep 17 15:13:54 EDT 2015 |
Re: Arrange objects based on list Hi !
Perhaps the link with the objects Customer/Government/Industry/Supplier is missing somewhere. ;) Perhaps try to replace the loop on the module with something like ...
// get the ref objects
Skip skp_ref = createString()
for o in m do {
if (! find(fileLines, probeAttr_(o, "object heading")) ) continue
put(skp_ref,probeAttr_(o, "object heading"), o)
}
// do the move part ;)
Object oref = null
for o in m do {
if ( !find(skp_ref, probeAttr_(o,"Object Heading"), oref) ) continue
move(o, last below oref)
o."Code Moved" = "Yes"
}
// clean the memory ...
delete fileLines
delete skp_ref
I have no DOORS client to test it, but this is the idea ;) Post your code if you are in trouble ! |
Re: Arrange objects based on list Boring preamble: ================= Every programmer knows not to do this, as is screws up the loop.
You are doing the same thing when you modify the order of objects from within the obj loop. Consider the following:
That loop works only on one object at all, since when the loop goes back and tries to find the "next" object, there isn't one since the 1st object is now the last one in the module. This is true for (?all?) loops of the form "for SomethingA in SomethingB" like "for link in object". You need to 1st stage the objects in a skip list, THEN start moving them around. ==================================
In your case you may have other problems since you are moving an object after another object, and I wonder what happens if you subsequently move THAT object. -Louie |
Re: Arrange objects based on list llandale - Sat Sep 26 17:41:12 EDT 2015 Boring preamble: ================= Every programmer knows not to do this, as is screws up the loop.
You are doing the same thing when you modify the order of objects from within the obj loop. Consider the following:
That loop works only on one object at all, since when the loop goes back and tries to find the "next" object, there isn't one since the 1st object is now the last one in the module. This is true for (?all?) loops of the form "for SomethingA in SomethingB" like "for link in object". You need to 1st stage the objects in a skip list, THEN start moving them around. ==================================
In your case you may have other problems since you are moving an object after another object, and I wonder what happens if you subsequently move THAT object. -Louie Hi Louie, Thanks for responding. I understand the loop thing that you mentioned, and I have the code "o."Code Moved" = "Yes"" which marks each object that the code moves. The "if statement" in the beginning of the loop checks to see if attribute code moved is empty, only then it touches that object. This was the only way I could think of, since moving the object last does not do the intended job. |
Re: Arrange objects based on list DOORS_user - Mon Sep 28 08:20:16 EDT 2015 Hi Louie, Thanks for responding. I understand the loop thing that you mentioned, and I have the code "o."Code Moved" = "Yes"" which marks each object that the code moves. The "if statement" in the beginning of the loop checks to see if attribute code moved is empty, only then it touches that object. This was the only way I could think of, since moving the object last does not do the intended job. Hmm ... The point of view of master Louie is formally the good one.
In the other hand, to add a test on the 'code moved' attribute just after the loop statment is enough to ensure that the job will be done properly. I take this opportunity to ask: Am i the only one to produce some ... 'not best' DXL in order to allow my users to modify my scripts by themselves ? To close this topic, seems that the 2 ways are working ... it depends how much you're confortable with these algos ;)
|
Re: Arrange objects based on list Thank you everyone for responding. I made a few modifications and it seems to be working now. |
Re: Arrange objects based on list llandale - Sat Sep 26 17:41:12 EDT 2015 Boring preamble: ================= Every programmer knows not to do this, as is screws up the loop.
You are doing the same thing when you modify the order of objects from within the obj loop. Consider the following:
That loop works only on one object at all, since when the loop goes back and tries to find the "next" object, there isn't one since the 1st object is now the last one in the module. This is true for (?all?) loops of the form "for SomethingA in SomethingB" like "for link in object". You need to 1st stage the objects in a skip list, THEN start moving them around. ==================================
In your case you may have other problems since you are moving an object after another object, and I wonder what happens if you subsequently move THAT object. -Louie Since you are moving objects "after" and may subsequently move that other object, I wonder if you need to do this:
This keeps moving objects until no more moves are needed. I'm also guessing there is a more effective algorithm. Perhaps before moving an object get an ordered list of all it's Sibling objects that come after it which have "Code Moved" as "Yes"; move each of these "after" after moving such an object. |